package com.hqhy.like.stock.service.impl;

import com.hqhy.like.stock.dao.persist.repository.ICategoryRepository;
import com.hqhy.like.stock.pojo.entity.Category;
import com.hqhy.like.stock.pojo.param.CategoryAddParam;
import com.hqhy.like.stock.pojo.vo.CategoryListItemVO;
import com.hqhy.like.stock.service.ICategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private ICategoryRepository categoryRepository;

    @Override
    public int insert(CategoryAddParam categoryAddParam) {
        log.debug("开始执行【插入类别】的业务，参数：{}", categoryAddParam);
        Category category = new Category();
        BeanUtils.copyProperties(categoryAddParam,category);
        return categoryRepository.insert(category);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据id删除类别】的业务，参数：{}", id);
        return categoryRepository.deleteById(id);
    }

    @Override
    public int updateById(CategoryListItemVO categoryListItemVO) {
        log.debug("开始执行【根据id删除类别】的业务，参数：{}", categoryListItemVO);
        Category category = new Category();
        BeanUtils.copyProperties(categoryListItemVO,category);
        return categoryRepository.updateById(category);
    }

    @Override
    public List<CategoryListItemVO> list() {
        log.debug("开始执行【显示类别列表】的业务");
        return categoryRepository.list();
    }


}
